﻿<%
    Dim currentDate, dealineDate, activeDays, expired
    Dim dateStr, participantName, participantId, participantTel, participantEmail, participantStamps, participantSouvenirs
    Dim conn, cmd
    Dim stamps, souvenirs, i, j
    
    currentDate = FormatDateTime(Now(),2)
    dealineDate = "2011/2/15"

    activeDays = DateDiff("d",currentDate,dealineDate)

    If activeDays < 1 Then
        expired = true
    Else
        expired = false

        dateStr = FormatDateTime(Now(),0)
        participantName = Request.Form("name")
        participantId = CDbl(Request.Form("id"))
        participantTel = CDbl(Request.Form("tel"))
        participantEmail = Request.Form("email")
        participantStamps = Request.Form("stamps")
        participantSouvenirs = Request.Form("souvenirs")

        Set conn = Server.CreateObject("ADODB.Connection")
        conn.Provider="Microsoft.Jet.OLEDB.4.0"
        conn.Open(Server.MapPath("/")+"\..\database\stamppoll2010.mdb")

        'Insert record
        Set cmd = Server.CreateObject("ADODB.Command")
        cmd.ActiveConnection = conn
        cmd.CommandText = "INSERT INTO tblParticipantVote(Name,IDNumber,Tel,Email,SouvenirVote1,SouvenirVote2,SouvenirVote3,StampVote1,StampVote2,StampVote3,VoteDateTime) VALUES(?,?,?,?,?,?,?,?,?,?,?)"
        cmd.CommandType = adCmdText
        cmd.Parameters.Append cmd.CreateParameter("@name",adVarWChar,adParamInput,50,0)
        cmd.Parameters.Append cmd.CreateParameter("@id",adNumeric,adParamInput,5,0)
        cmd.Parameters.Append cmd.CreateParameter("@tel",adNumeric,adParamInput,8,0)
        cmd.Parameters.Append cmd.CreateParameter("@email",adVarChar,adParamInput,50,0)
        cmd.Parameters.Append cmd.CreateParameter("@souvenir1",adVarChar,adParamInput,50,0)
        cmd.Parameters.Append cmd.CreateParameter("@souvenir2",adVarChar,adParamInput,50,0)
        cmd.Parameters.Append cmd.CreateParameter("@souvenir3",adVarChar,adParamInput,50,0)
        cmd.Parameters.Append cmd.CreateParameter("@stamp1",adVarChar,adParamInput,50,0)
        cmd.Parameters.Append cmd.CreateParameter("@stamp2",adVarChar,adParamInput,50,0)
        cmd.Parameters.Append cmd.CreateParameter("@stamp3",adVarChar,adParamInput,50,0)
        cmd.Parameters.Append cmd.CreateParameter("@datetime",adVarChar,adParamInput,50,0)
        cmd.Parameters("@name") = Request.Form("name")
        cmd.Parameters("@id") = participantId
        cmd.Parameters("@tel") = participantTel
        cmd.Parameters("@email") = participantEmail
        cmd.Parameters("@souvenir1") = "0"
        cmd.Parameters("@souvenir2") = "0"
        cmd.Parameters("@souvenir3") = "0"
        cmd.Parameters("@stamp1") = "0"
        cmd.Parameters("@stamp2") = "0"
        cmd.Parameters("@stamp3") = "0"
        cmd.Parameters("@datetime") = dateStr
        souvenirs = split(participantSouvenirs,",")
        For i = LBound(souvenirs) to UBound(souvenirs)
            cmd.Parameters("@souvenir" & i+1) = souvenirs(i)
        Next
        stamps = split(participantStamps,",")
        For j = LBound(stamps) to UBound(stamps)
            cmd.Parameters("@stamp" & j+1) = stamps(j)
        Next
        
        cmd.Execute
        conn.Close
    End If
 %>